package com.icoolkj.learn.juc.base;

import lombok.extern.slf4j.Slf4j;

/**
 * @author icoolkj
 * @version 1.0
 * @description 中断机制案例：中断 sleep 的线程，会清空中断状态
 * @createDate 2025/03/04 13:40
 */
@Slf4j
public class ThreadInterruptDemo2 {
    public static void main(String[] args) {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                        // break;

                        //Thread.currentThread().interrupt();
                    }
                    log.info("中断状态：{}", Thread.currentThread().isInterrupted());
                }
            }
        }, "t1");

        t1.start();

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        t1.interrupt();
        log.info("中断状态：{}", t1.isInterrupted());

    }
}
